<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="bs/css/bootstrap.css">
    <link rel="stylesheet" href="layui/css/layui.css">
    <script src="layui/layui.js"></script>
    <script src="bs/js/bootstrap.js"></script>
    <link rel="stylesheet" href="css/body-list.css">
</head>
<body>
<div style="margin: 5% 20%;">
    <form class="layui-form" action="">

        <div class="layui-form-item  layui-col-xs12">
            <div class="layui-inline ">
                <label class="layui-form-label">主题名称:</label>
                <div class="layui-input-inline">
                    <input type="tel" id="bh" name="bh" autocomplete="off" class="layui-input" value="">
                </div>
            </div>
        </div>

        <div class="layui-form-item layui-col-xs12">
            <div class="layui-inline layui-col-xs12">
                <label class="layui-form-label">主题apk包名:</label>
                <div class="layui-input-inline">
                    <input type="text" id="Name" name="Name" autocomplete="off" class="layui-input" value="">
                </div>
            </div>
        </div>

        <div class="layui-form-item layui-col-xs12">
            <div class="layui-inline">
                <label class="layui-form-label">主题类型:</label>
                <div class="layui-input-inline">
                    <select name="type1" id="type1" >
                        <option value="0">酒店</option>
                        <option value="1">足浴</option>
                    </select>
                </div>
            </div>
        </div>

        <div class="layui-form-item layui-col-xs12">
            <div class="layui-inline">
                <label class="layui-form-label">主题状态:</label>
                <div class="layui-input-inline">
                    <select name="type2" id="type2" >
                        <option value="0">启用</option>
                        <option value="1">禁用</option>
                    </select>
                </div>
            </div>
        </div>

        <div class="layui-upload">
            <button type="button" class="layui-btn" id="test1">主题图片：</button>
            <div class="layui-upload-list" style="width: 200px;height: 200px;border:1px solid black ">
                <img class="layui-upload-img" id="demo1" style="width: 200px;height: 200px;">
                <p id="demoText"></p>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn" lay-filter="demo1" >提交</button>
            </div>
        </div>
    </form>
</div>

</body>
<script>
    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;
        form.render();



        //监听提交
        form.on('submit(demo1)', function(data){
            layer.alert(JSON.stringify(data.field), {
                title: '最终的提交信息'
            })
            return false;
        });

        //表单赋值
        layui.$('#LAY-component-form-setval').on('click', function(){
            form.val('example', {
                "username": "贤心" // "name": "value"
                ,"password": "123456"
                ,"interest": 1
                ,"like[write]": true //复选框选中状态
                ,"close": true //开关状态
                ,"sex": "女"
                ,"desc": "我爱 layui"
            });
        });

        //表单取值
        layui.$('#LAY-component-form-getval').on('click', function(){
            var data = form.val('example');
            alert(JSON.stringify(data));
        });

    });
</script>
<script>
    layui.use('upload', function(){
        var $ = layui.jquery
            ,upload = layui.upload;

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#test1'
            ,url: '/upload/'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                //如果上传失败
                if(res.code > 0){
                    return layer.msg('上传失败');
                }
                //上传成功
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });



        // //同时绑定多个元素，并将属性设定在元素上
        // upload.render({
        //     elem: '.demoMore'
        //     ,before: function(){
        //         layer.tips('接口地址：'+ this.url, this.item, {tips: 1});
        //     }
        //     ,done: function(res, index, upload){
        //         var item = this.item;
        //         console.log(item); //获取当前触发上传的元素，layui 2.1.0 新增
        //     }
        // })
        //
        // /



        //多文件列表示例
        // var demoListView = $('#demoList')
        //     ,uploadListIns = upload.render({
        //     elem: '#testList'
        //     ,url: '/upload/'
        //     ,accept: 'file'
        //     ,multiple: true
        //     ,auto: false
        //     ,bindAction: '#testListAction'
        //     ,choose: function(obj){
        //         var files = this.files = obj.pushFile(); //将每次选择的文件追加到文件队列
        //         //读取本地文件
        //         obj.preview(function(index, file, result){
        //             var tr = $(['<tr id="upload-'+ index +'">'
        //                 ,'<td>'+ file.name +'</td>'
        //                 ,'<td>'+ (file.size/1014).toFixed(1) +'kb</td>'
        //                 ,'<td>等待上传</td>'
        //                 ,'<td>'
        //                 ,'<button class="layui-btn layui-btn-xs demo-reload layui-hide">重传</button>'
        //                 ,'<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete">删除</button>'
        //                 ,'</td>'
        //                 ,'</tr>'].join(''));
        //
        //             //单个重传
        //             tr.find('.demo-reload').on('click', function(){
        //                 obj.upload(index, file);
        //             });
        //
        //             //删除
        //             tr.find('.demo-delete').on('click', function(){
        //                 delete files[index]; //删除对应的文件
        //                 tr.remove();
        //                 uploadListIns.config.elem.next()[0].value = ''; //清空 input file 值，以免删除后出现同名文件不可选
        //             });
        //
        //             demoListView.append(tr);
        //         });
        //     }
        //     ,done: function(res, index, upload){
        //         if(res.code == 0){ //上传成功
        //             var tr = demoListView.find('tr#upload-'+ index)
        //                 ,tds = tr.children();
        //             tds.eq(2).html('<span style="color: #5FB878;">上传成功</span>');
        //             tds.eq(3).html(''); //清空操作
        //             return delete this.files[index]; //删除文件队列已经上传成功的文件
        //         }
        //         this.error(index, upload);
        //     }
        //     ,error: function(index, upload){
        //         var tr = demoListView.find('tr#upload-'+ index)
        //             ,tds = tr.children();
        //         tds.eq(2).html('<span style="color: #FF5722;">上传失败</span>');
        //         tds.eq(3).find('.demo-reload').removeClass('layui-hide'); //显示重传
        //     }
        // });



    });
</script>
</html>